<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Java Programming</title>
<link rel="shortcut icon" href="images/idenewlogo.png">
<link href="http://www.uark.edu/rd_vcad/inc/jQuery/prettify/prettify.css" type="text/css" rel="stylesheet" /> 
<script type="text/javascript" src="http://www.uark.edu/rd_vcad/inc/jQuery/prettify/prettify.js"></script>
<script language="Javascript" type="text/javascript" src="js/editarea_0_8_2/edit_area/edit_area_full.js"></script>
<script language="javascript" type="text/javascript">

		// callback functions
		function my_save(id, content){
			alert("Here is the content of the EditArea '"+ id +"' as received by the save callback function:\n"+content);
		}
		
		function my_load(id){
			editAreaLoader.setValue(id, "The content is loaded from the load_callback function into EditArea");
		}
		function my_load_main(id,content){
			editAreaLoader.setValue(id, content);
		}
		function test_setSelectionRange(id){
			editAreaLoader.setSelectionRange(id, 100, 150);
		}
		
		function test_getSelectionRange(id){
			var sel =editAreaLoader.getSelectionRange(id);
			alert("start: "+sel["start"]+"\nend: "+sel["end"]); 
		}
		
		function test_setSelectedText(id){
			text= "[REPLACED SELECTION]"; 
			editAreaLoader.setSelectedText(id, text);
		}
		
		function test_getSelectedText(id){
			alert(editAreaLoader.getSelectedText(id)); 
		}
		
		function editAreaLoaded(id){
			if(id=="example_2")
			{
				open_file1();
				open_file2();
			}
		}
		
		function open_file1()
		{
			var new_file= {id: "to\\ ÃÂÃÂÃÂÃÂÃÂÃ¢ÂÂÃÂÃÂ© # ÃÂÃÂÃÂÃÂ¢ÃÂÃ¢ÂÂÃÂÃ¢ÂÂÃÂÃ¢ÂÂÃÂÃÂ¬ to", text: "$authors= array();\n$news= array();", syntax: 'php', title: 'beautiful title'};
			editAreaLoader.openFile('example_2', new_file);
		}
		
		function open_file2()
		{
			var new_file= {id: "Filename", text: "<a href=\"toto\">\n\tbouh\n</a>\n<!-- it's a comment -->", syntax: 'html'};
			editAreaLoader.openFile('example_2', new_file);
		}
		
		function close_file1()
		{
			editAreaLoader.closeFile('example_2', "to\\ ÃÂÃÂÃÂÃÂÃÂÃ¢ÂÂÃÂÃÂ© # ÃÂÃÂÃÂÃÂ¢ÃÂÃ¢ÂÂÃÂÃ¢ÂÂÃÂÃ¢ÂÂÃÂÃÂ¬ to");
		}
		
		function toogle_editable(id)
		{
			editAreaLoader.execCommand(id, 'set_editable', !editAreaLoader.execCommand(id, 'is_editable'));
		}
	
	</script>
</head>
<script type="text/javascript">
	function findKeyWords(){
		var content = document.getElementById("myJavaForm:codeTextArea").value;
		alert(content);
		var splitArr = content.split(" ");
		var keyWords ="abstract continue for new switch assert	default	goto package synchronized boolean do if	private	this break double implements protected throw byte else import public throws case enum instanceof return transient catch extends int short try char final interface static void class finally long strictfp volatile const float native super while"
		var keyWordsArr = keyWords.split(" ");
		//alert("class length "+splitArr.length);
		//alert("keyWords length "+keyWordsArr.length);
		for(i=0;i<splitArr.length;i++){
			// alert(splitArr[i]);
			//for(j=0;j<keyWordsArr.length;j++){
				//if(splitArr[i]==keyWordsArr[j]){
					// alert("matched:"+splitArr[i]);
					document.getElementById("myJavaForm:codeTextArea").value="<b>"+content+"</b>";
				//}
			//}
		}
		
	}
	function getSelectedClass(){
		var selClass = document.getElementById("myJavaForm:mysele").value;
		alert("selClass:"+selClass);
	}
	function getSelClass(rowIndex,param){
		if(param=='delete'){
			var file = confirm("Are You Sure You Want To Delete" + document.getElementById('myJavaForm:dataTableId:'+rowIndex+':classNameId').innerHTML + "File");
		  if(file){
			  //alert("Are You Sure To Delete This Java File");
			  document.getElementById('myJavaForm:hiddenFullPath').value = document.getElementById('myJavaForm:dataTableId:'+rowIndex+':classNameId').innerHTML;
			  return true;
		  }else{
				//alert("inside else");
			  return false;  
		  }
		  
     	}  
		document.getElementById('myJavaForm:hiddenFullPath').value = document.getElementById('myJavaForm:dataTableId:'+rowIndex+':classNameId').innerHTML;
		//alert(rowIndex);
		//alert(document.getElementById('myJavaForm:dataTableId:'+rowIndex+':classNameId').innerHTML);
		//document.getElementById('myJavaForm:hiddenFullPath').value = document.getElementById('myJavaForm:dataTableId:'+rowIndex+':classNameId').innerHTML;
		return true;
	}
	function recentFileOpen(recentFileIndex){
		//alert("recentFileOpen:"+recentFileIndex);
		document.getElementById('myJavaForm:hiddenFullPath').value=document.getElementById('myJavaForm:recentFileDataList:'+recentFileIndex+':receId').innerHTML;
		//alert(document.getElementById('myJavaForm:hiddenFullPath').value);
	}
	function getSelJarToDelete(rowIndex){
		var file = confirm("Are You Sure You Want To Delete" + document.getElementById('myJavaForm:jarDataTableId:'+rowIndex+':jarNameId').innerHTML + "File");
		if(file){
			document.getElementById('myJavaForm:hiddenJarFullPath').value = document.getElementById('myJavaForm:jarDataTableId:'+rowIndex+':jarNameId').innerHTML;
		}
		//alert(rowIndex);
		//alert(document.getElementById('myJavaForm:dataTableId:'+rowIndex+':classNameId').innerHTML);
		//document.getElementById('myJavaForm:hiddenJarFullPath').value = document.getElementById('myJavaForm:jarDataTableId:'+rowIndex+':jarNameId').innerHTML;
		//alert(document.getElementById('myJavaForm:hiddenJarFullPath').value);
	}
	function createMainMethod(){
		//alert("with in create main method ");
		//alert(document.getElementById('myJavaForm:mainMethodId').checked);
		checkForExtension();
		if(document.getElementById('myJavaForm:mainMethodId').checked){
			editAreaLoader.init({id : "myJavaForm:codeTextArea",syntax: "java",start_highlight: true});
			var className = document.getElementById('myJavaForm:classNameId').value;
			//alert("className "+className);
			var currentUserName=document.getElementById('myJavaForm:srcId').innerHTML;
			if(className!=null){
				//alert("with in the if condition");
				if(className.indexOf(".java")>0){
					//alert("it contains java ");
					className = className.substring(0,className.indexOf(".java"));
					//alert("modified class "+className);
					
					document.getElementById('myJavaForm:codeTextArea').value="public class "+className+"{\n    public static void main(String args[]){ \n		//TODO enter your program	 \n	}\n}";
					var main_java = "public class "+className+"{\n    public static void main(String args[]){ \n		//TODO enter your program \n		System.out.println();	  \n   }\n}";
					my_load_main('myJavaForm:codeTextArea',main_java);  
				}else{
					var non_main = "public class "+className+"{\n    public static void main(String args[]){ \n		//TODO enter your program	 \n	}\n}";
					document.getElementById('myJavaForm:codeTextArea').value="public class "+className+"{\n    public static void main(String args[]){ \n		//TODO enter your program \n		System.out.println();	 \n}\n}";
					my_load_main('myJavaForm:codeTextArea',non_main);
				}
			}
			document.getElementById('myJavaForm:mainMethodId').disabled =true;
		}else{
			document.getElementById('myJavaForm:codeTextArea').value="";
		}
		
		
	}
	function disablecheckbox(){
		var ext="java";
		var fileName = document.getElementById('myJavaForm:classNameId').value;
		if(fileName!=null){
			//alert("with in the if condition");
			if(fileName.indexOf(".")>0){
				ext = fileName.substring(fileName.indexOf(".")+1,fileName.length);
			}
		}
		//alert("ext:"+ext);
		if(ext=="properties" || ext=="txt"){
			editAreaLoader.init({id : "myJavaForm:codeTextArea",syntax: "html",start_highlight: true,show_line_colors: true});
		}else{
			editAreaLoader.init({id : "myJavaForm:codeTextArea",syntax: ext,start_highlight: true,show_line_colors: true});
		}
		document.getElementById("myJavaForm:mainMethodId").style.visibility="hidden";
		document.getElementById("myJavaForm:createMainId").style.visibility="hidden";
		toggleSaveRunButton();
		//window.open('ideIntro.jsf','open_window','menubar, toolbar, location, directories, status, scrollbars, resizable, dependent, width=1000, height=700, left=0, top=0');
	}
	function enableCheckBox(){
		document.getElementById('myJavaForm:mainMethodId').disabled =false;
	}
	function toggleSaveRunButton(){
		var fileName = document.getElementById('myJavaForm:classNameId').value;
		var codeArea = document.getElementById('myJavaForm:codeTextArea').value;
		if(fileName!=null){
			//alert("with in the if condition");
			if(fileName.indexOf(".")>0){
				var ext = fileName.substring(fileName.indexOf(".")+1,fileName.length);
				//alert("ext:"+ext);
				if(ext=="ja" || ext=="jav" || ext=="java"){
					//document.getElementById("myJavaForm:mainMethodId").disabled= false;
					//document.getElementById("myJavaForm:createMainId").disabled= false;
					if(codeArea == null || codeArea.length <= 0){
						document.getElementById("myJavaForm:mainMethodId").style.visibility="visible";
						document.getElementById("myJavaForm:createMainId").style.visibility="visible";
					}
					document.getElementById("myJavaForm:runfirst").style.visibility="visible";
					document.getElementById("myJavaForm:run").style.visibility="visible";
					document.getElementById('myJavaForm:mainMethodId').disabled =false;
					// editAreaLoader.init({id : "myJavaForm:codeTextArea",syntax: "java",start_highlight: true,show_line_colors: true});
					
				}else if(ext=="x" || ext=="xm" || ext=="xml"){
					document.getElementById("myJavaForm:mainMethodId").style.visibility="hidden";
					document.getElementById("myJavaForm:createMainId").style.visibility="hidden";
					document.getElementById("myJavaForm:runfirst").style.visibility="hidden";
					document.getElementById("myJavaForm:run").style.visibility="hidden";
					// editAreaLoader.init({id : "myJavaForm:codeTextArea",syntax: "xml",start_highlight: true,show_line_colors: true});
					
				}else if(ext=="ht" || ext=="htm" || ext=="html"){
					document.getElementById("myJavaForm:mainMethodId").style.visibility="hidden";
					document.getElementById("myJavaForm:createMainId").style.visibility="hidden";
					document.getElementById("myJavaForm:runfirst").style.visibility="hidden";
					document.getElementById("myJavaForm:run").style.visibility="hidden";
					// editAreaLoader.init({id : "myJavaForm:codeTextArea",syntax: "html",start_highlight: true,show_line_colors: true});
				}else if(ext=="prop" || ext=="properti" || ext=="properties"){
					document.getElementById("myJavaForm:mainMethodId").style.visibility="hidden";
					document.getElementById("myJavaForm:createMainId").style.visibility="hidden";
					document.getElementById("myJavaForm:runfirst").style.visibility="hidden";
					document.getElementById("myJavaForm:run").style.visibility="hidden";
					//editAreaLoader.init({id : "myJavaForm:codeTextArea",syntax: "html",start_highlight: true,show_line_colors: true});
				}else if(ext=="t" || ext=="tx" || ext=="txt"){
					document.getElementById("myJavaForm:mainMethodId").style.visibility="hidden";
					document.getElementById("myJavaForm:createMainId").style.visibility="hidden";
					document.getElementById("myJavaForm:runfirst").style.visibility="hidden";
					document.getElementById("myJavaForm:run").style.visibility="hidden";
					// editAreaLoader.init({id : "myJavaForm:codeTextArea",syntax: "html",start_highlight: true,show_line_colors: true});
				}
			}
		}
		return true;
	}
	function checkForExtension(){
		var fileName = document.getElementById('myJavaForm:classNameId').value;
		if(fileName!=null){
			//alert("with in the if condition");
			if(fileName.indexOf(".")>0){
				var ext = fileName.substring(fileName.indexOf(".")+1,fileName.length);
				//alert("checkForExtension:ext     "+ext);
				if(ext != "java" && ext != "xml" && ext != "html" && ext != "properties" && ext != "txt"){
					alert("Extension should be valid  \n For instance  \n .java or \n .properties or \n .txt or \n .xml or \n .html");
					return false;
				}
			}else{
				alert("File ext should be required \n For instance  \n .java or \n .properties or \n .txt or \n .xml or \n .html");
				return false;
			}
		}
		return true;
	}
	function getKeys(){
		alert("with in getKeys");
	}
</script>
<body onload="disablecheckbox();" style="width:1200px;height:900px;">
	<h:form id="myJavaForm">
	<div style="width: 1250px; overflow: auto;">
		<div style="height: 770px; width: 270px; border: groove;border-color: red; overflow: auto;float: left;" >
			<div>
							<div>
								<h:outputText style="white-space:nowrap;font-size: 9pt" value="Current User:"/>
								<h:outputText style="white-space:nowrap;font-weight:bold; font-size: 11pt" id="srcId" value="#{userDetailsBean.username}"/>
							</div>
							<div>	
								<h:commandLink id="changePasswordId" action="#{javaManagedBean.changePassword}" value="change password" style="color: green; font-size: 10pt"/>
								<h:outputText id="changePsdEmptyId" value=" "/>
								<h:commandLink id="changePsdLinkId" action="#{javaManagedBean.logout}" value="logout" style="color: red; font-size: 10pt"/>
							</div>
							<div>	
							<t:dataTable var="classNameVar" rowIndexVar="currentRow" 
										id="dataTableId" style="text-align=center;width: 250px"
										bgcolor="#F1F1F1" border="8" cellpadding="4" cellspacing="2"
										frame="hsides" rules="all" width="50%"
										rowClasses="TableRow1,TableRow2" columnClasses="TableColumn"
										styleClass="TableClass" headerClass="TableHeader" footerClass="TableFooter"
										value="#{javaManagedBean.listOfFiles}" rows="15">
								<f:facet name="header">
									<h:outputText value="Package explorer" />
								</f:facet>		
								<t:column style="color:green; font-weight:bold" headerstyle="background-color:#99CCFF;">
	      							<f:facet name="header"><h:outputText style="white-space:nowrap" value="Java File"/></f:facet>
	      							<h:outputText id="classNameId" style="align:left; font-size: 10pt" value="#{classNameVar.className}"/>
	      						</t:column>
	    						<t:column style="color:green; font-weight:bold" headerstyle="background-color:#99CCFF;">
	      							<f:facet name="header"><h:outputText style="white-space:nowrap;" value="Open"/></f:facet>
	      							<h:commandButton value="Open" id="openAction" action="#{javaManagedBean.openAction}" onclick="return getSelClass('#{currentRow}','open')"  title="click to open file"/>
	      						</t:column>
	      						<t:column style="color:green; font-weight:bold" headerstyle="background-color:#99CCFF;">	
	      						    <f:facet name="header"><h:outputText style="white-space:nowrap" value="Delete"/></f:facet>
	      							<h:commandButton value="Del" id="deleteAction" action="#{javaManagedBean.deleteAction}" onclick="return getSelClass('#{currentRow}','delete')" title="click to Delete file"/>
	    						</t:column>	
							</t:dataTable>
								<t:dataScroller id="dataScrollerId" for="dataTableId" fastStep="10"
							        pageIndexVar="pageIndex" renderFacetsIfSinglePage="true"
							        pageCountVar="pageCount" paginator="true" paginatorMaxPages="9"
							        immediate="true" paginatorTableClass="paginator"
									paginatorActiveColumnStyle="font-weight:bold;font-size:30px;" 
									rendered="#{javaManagedBean.disNavigation}">
							        <f:facet name="first">
							            <t:outputText value="First" style="font-size: 9pt"/>
							        </f:facet>
							        <f:facet name="last">
							            <t:outputText value="Last" style="font-size: 9pt"/>
							        </f:facet>
							        <f:facet name="previous">
							            <t:outputText value="Previous" style="font-size: 9pt"/>
							        </f:facet>
							        <f:facet name="next">
							            <t:outputText value="Next" style="font-size: 9pt"/>
							        </f:facet>
							  </t:dataScroller>
							 </div>     
					    <h:inputHidden id="hiddenFullPath" value="#{javaManagedBean.selClassName}"></h:inputHidden>
			</div>
		</div>
		<div style="height: 770px;width: 690px;border: groove;border-color: red; overflow: auto;float: left;">
		<h:messages style="color:red"/>
			<h:panelGrid columns="1" cellspacing="3" cellpadding="3" border="3" title="Java Online IDE" style="height: 600px; width: 680px; color: black; background: lightgray;">
				
					<h:panelGroup>
						<h:outputLabel id="enterfileId" value="Enter File Name" style="align: center; font-size: 10pt"/>
						<h:inputText id="classNameId" value="#{javaManagedBean.className}" onkeyup="return toggleSaveRunButton()"/>
						<h:selectBooleanCheckbox id="mainMethodId" onclick="createMainMethod();"/>
						<h:outputLabel id="createMainId" value="create class with main method" style="font-size: 10pt"/>
						<h:commandButton id="clearIdfirst" action="#{javaManagedBean.clear}" value="Clear" style="align: center; color: black; background: lightgray; font-size: 10pt"/>
						<h:commandButton id="onlySaveIdfirst" action="#{javaManagedBean.saveProgram}" value="Save" style="align: center; color: black; background: lightgray; font-size: 10pt" onclick="return checkForExtension()"/>
						<h:commandButton id="runfirst" action="#{javaManagedBean.runProgram}" value="Save && Run"  style="align: center; color: black; background: lightgray; font-size: 10pt" onclick="return checkForExtension()"/>
						 
					</h:panelGroup>	
					<h:panelGroup>
						<h:outputLabel id="recentViewId" value="recent views:" style="align: center; font-size: 9pt"/>
						<t:dataList id="recentFileDataList" var="recentVar" value="#{javaManagedBean.recentFilesList}" rowIndexVar="rowIndex">
						
						<h:commandLink  id="receId" value="#{recentVar.recentFile}" action="#{javaManagedBean.openAction}" onclick="recentFileOpen(#{rowIndex})" style="align: center; font-size: 9pt" title="click to open file"/>
						<h:commandLink id="receDelId" action="#{javaManagedBean.deleteRecent}" onclick="recentFileOpen(#{rowIndex})" title="click to close file"><t:graphicImage  url="images/close_small.png"/></h:commandLink>
						<h:outputLabel id="emptyid" value=" " style="align: center; font-size: 5pt"/>
						</t:dataList>
					</h:panelGroup>		
					<h:panelGroup>
						<t:inputTextarea id="codeTextArea" value="#{javaManagedBean.codeText}" style="width: 680px; height: 486px" wrap="off" onkeydown="getKeys();"/>
					</h:panelGroup>
					<h:panelGroup style="width: 623px; ">
						<h:commandButton id="clearId" action="#{javaManagedBean.clear}" value="Clear" style="align: center; color: black; background: lightgray;"/>
					    <h:commandButton id="onlySaveId" action="#{javaManagedBean.saveProgram}" value="Save" style="align: center; color: black; background: lightgray;" onclick="return checkForExtension()"/>
						<h:commandButton id="run" action="#{javaManagedBean.runProgram}" value="Save && Run"  style="align: center; color: black; background: lightgray;" onclick="return checkForExtension()"/>
						
					</h:panelGroup> 
					<h:panelGroup style="width: 625px; ">
						<h:outputLabel value="Console" style="align: center; color: black; background: lightgray; font-size: 10pt"/>
					</h:panelGroup>
					<h:panelGroup>
<t:inputTextarea id="consoleTextArea" value="#{javaManagedBean.output}" style="#{javaManagedBean.consoleColor};width: 680px; height: 126px" wrap="off"/>
					</h:panelGroup>
					
					
					
			</h:panelGrid>
		</div>
		
		<div style="height: 770px;width: 265px;border:groove;border-color: red; overflow: auto;float: left;">
			<h:panelGrid columns="1" cellspacing="3" cellpadding="3" border="3" style="height: 600px; width: 280px; color: black; background: lightgray; vertical-align: top">
					<h:panelGroup style="height: 10px;">
						<h:outputLabel id="reqJarId" value="Add Required jar files(click on jar and save&run selected jar file will be class path)" style="font-size: 10pt"/>
					</h:panelGroup>
					<h:panelGroup style="height: 250px; font-size: 10pt">
						<h:selectManyMenu id="selectJarId" value="#{javaManagedBean.selectedJarList}" style="height: 137px; font-size: 10pt">
						  	<f:selectItems value="#{javaManagedBean.listOfJarFiles}"/>
						</h:selectManyMenu>
					</h:panelGroup>
						<t:dataTable var="jarNameVar" rowIndexVar="currentJarRow" 
									 id="jarDataTableId" style="text-align=center;height: 115px"
								     value="#{javaManagedBean.availableJarList}" rows="15"
								     bgcolor="#F1F1F1" border="8" cellpadding="4" cellspacing="2"
									 frame="hsides" rules="all" width="90%"
									 rowClasses="TableRow1,TableRow2" columnClasses="TableColumn"
									 styleClass="TableClass" headerClass="TableHeader" footerClass="TableFooter" >
							
							<f:facet name="header">
									<h:outputText value="Jar files in class path" />
							</f:facet>	     
							<t:column>
      							<h:outputText id="jarNameId" style="align:left; font-size: 10pt" value="#{jarNameVar.jarName}"/>
      						</t:column>
    						<t:column>	
      							<h:commandButton value="Delete" id="deleteJar" action="#{javaManagedBean.deleteJar}" onclick="getSelJarToDelete('#{currentJarRow}')" title="click to Delete file"/>
    						</t:column>
    					</t:dataTable>
					<h:inputHidden id="hiddenJarFullPath" value="#{javaManagedBean.selJarToDel}"></h:inputHidden>
					<h:panelGroup>
						<h:outputText value="We have provided the jar files which are frequently used. In case While running the java programs , if you need more jar files pls mail to below address we will add the required jar files" style="font-size: 10pt"/>
					</h:panelGroup>
					<h:panelGroup>
						<h:outputText value="If any queries and feedback on this online ide pls feel free to mail" style="font-size: 10pt"></h:outputText>
					</h:panelGroup>
					<h:panelGroup>
						<h:outputText value="support@onlinejavaide.com" style="color:brown"></h:outputText>
					</h:panelGroup>	
			</h:panelGrid>
		</div>
	</div>
	</h:form>

</body>
</html>
</f:view>